﻿using B.S.Data.MES.API.Applications.ProcessmaintenanceApplications.Command;
using B.S.Domain.Process.ProcessmaintenanceModel;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.ProcessmaintenanceApplications.Horter
{
    public class UpdateProcessmaintenanceCommandHorter:IRequestHandler<UpdateProcessmaintenanceCommand,APIRequst<int>>
    {
        IBaseRepository<Processmaintenance> repository;

        public UpdateProcessmaintenanceCommandHorter(IBaseRepository<Processmaintenance> repository)
        {
            this.repository = repository;
        }

        public async Task<APIRequst<int>> Handle(UpdateProcessmaintenanceCommand request, CancellationToken cancellationToken)
        {
            var res = new APIRequst<int>();
            var source = await repository.GetById(request.Id);
            if (source == null)
            {

                res.Msg = "没有查找到您所需要的数据";
                return res;
            }
           

            source.ProcessmaintenanceEncode = request.ProcessmaintenanceEncode;
            source.ProcessmaintenanceName = request.ProcessmaintenanceName;
            source.ProcessmaintenanceType = request.ProcessmaintenanceType;
            source.ProcessmaintenanceReportingmode = request.ProcessmaintenanceReportingmode;
            source.ProcessmaintenanceDescription = request.ProcessmaintenanceDescription;
            source.ProcessmaintenanceUpdateTime = DateTime.Now;

            var del = await repository.Update(source);
            if (del > 0)
            {
                res.Msg = "修改成功";
                res.Data = del;
                return res;
            }
            else
            {

                res.Msg = "修改失败";
                res.Data = del;
                return res;
            }
        }
    }
}
